<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>首页 - 光年(Light Year Admin)后台管理系统模板</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">

    <link th:href="@{/admin/css/bootstrap.min.css}" type="text/css" rel="stylesheet">
    <link th:href="@{/admin/css/materialdesignicons.min.css}" type="text/css" rel="stylesheet">
    <link th:href="@{/admin/css/style.min.css}" type="text/css" rel="stylesheet">
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a th:href="@{/manage/index}"><img src="/admin/images/logo-sidebar.png" title="LightYear"
                                                   alt="LightYear"/></a>
            </div>
            <div class="lyear-layout-sidebar-scroll">

                <nav class="sidebar-main">
                    <ul class="nav nav-drawer">
                        <li class="nav-item active">
                            <a th:href="@{/manage/index}"><i class="mdi mdi-home"></i>后台首页</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/toNovel}"><i class="mdi mdi-book-open"></i> 书籍管理</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/recharge}"><i class="mdi mdi-diamond"></i> 充值管理</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/toComment}"><i class="mdi mdi-record"></i> 评论管理</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/toPassApply}"><i class="mdi mdi-compass"></i> 审批作家</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/system/param}"><i class="mdi mdi-brightness-5"></i> 系统设置</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/system/log}"><i class="mdi mdi-grease-pencil"></i> 系统日志</a>
                        </li>
                    </ul>
                </nav>
            </div>

        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 后台首页 </span>
                    </div>

                    <ul class="topbar-right">
                        <li class="dropdown dropdown-profile">
                            <a href="javascript:void(0)" data-toggle="dropdown">
                                <img class="img-avatar img-avatar-48 m-r-10" th:src="${session.loginUser.imgSrc}"
                                     alt="笔下光年"/>
                                <span th:text="${session.loginUser.userName}"> <span class="caret"></span></span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-right">
                                <li><a th:href="@{/manage/toInfo}"><i class="mdi mdi-account"></i> 个人信息</a></li>
                                <li><a th:href="@{/manage/toChangePwd}"><i class="mdi mdi-lock-outline"></i> 修改密码</a>
                                </li>
                                <li><a th:href="@{/index}"><i class="mdi mdi-lock-outline"></i> 回到门户网站</a>
                                </li>
                                <li class="divider"></li>
                                <li><a th:href="@{/manage/logout}"><i class="mdi mdi-logout-variant"></i> 退出登录</a>
                                </li>
                            </ul>
                        </li>
                    </ul>

                </div>
            </nav>

        </header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-primary">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">今日日充值次数</p>
                                    <p id="today-order" class="h3 text-white m-b-0 fa-1-5x"></p>
                                </div>
                                <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                        class="mdi mdi-currency-cny fa-1-5x"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-danger">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">在线用户总数</p>
                                    <p id="online-count" class="h3 text-white m-b-0 fa-1-5x"></p>
                                </div>
                                <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                        class="mdi mdi-account fa-1-5x"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-success">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">小说下载总次数</p>
                                    <p id="download-count" class="h3 text-white m-b-0 fa-1-5x"></p>
                                </div>
                                <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                        class="mdi mdi-arrow-down-bold fa-1-5x"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-6 col-lg-3">
                        <div class="card bg-purple">
                            <div class="card-body clearfix">
                                <div class="pull-right">
                                    <p class="h6 text-white m-t-0">总充值次数</p>
                                    <p id="order-count" class="h3 text-white m-b-0 fa-1-5x"></p>
                                </div>
                                <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                        class="mdi mdi-comment-outline fa-1-5x"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">

                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-header">
                                <h4>系统访问压力图</h4>
                            </div>
                            <div class="card-body">
                                <div id="system-main" style="width: 600px;height: 300px"></div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-header">
                                <h4>各金额充值数</h4>
                            </div>
                            <div class="card-body">
                                <div id="order-main" style="width: 600px;height: 300px"></div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<script type="text/javascript" th:src="@{/admin/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/admin/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/admin/js/perfect-scrollbar.min.js}"></script>
<script type="text/javascript" th:src="@{/admin/js/main.min.js}"></script>

<!--图表插件-->
<script type="text/javascript" th:src="@{/js/echarts.min.js}"></script>

<script type="text/javascript">

    //使用ajax异步请求获取系统访问数据
    $.ajax({
        url: "/manage/system/power",
        method: "post",
        success: function (dataList) {
            //初始化表格
            var myChart = echarts.init(document.getElementById('system-main'));
            //设置商品号
            var names = [];
            //商品销售额
            var productAmount = [];
            //遍历获取商品号
            for (let i = 0; i < dataList.length; i++) {
                names.push(dataList[i].hour);
                productAmount.push(dataList[i].value);
            }
            //设置表格参数
            option = {
                xAxis: {
                    type: 'category',
                    data: names,
                },
                yAxis: {
                    type: 'value',
                    names: '频率',
                },
                series: [{
                    data: productAmount,
                    type: 'line',
                    showBackground: true,
                    backgroundStyle: {
                        color: 'rgba(220, 220, 220, 0.8)'
                    }
                }]
            };

            //给表格设置数据
            myChart.setOption(option);
        },
    });


    //使用ajax异步请求
    $.ajax({
        url: "/manage/order/map",
        method: "post",
        success: function (dataList) {
            //初始化表格
            var myChart = echarts.init(document.getElementById('order-main'));
            //设置商品号
            var names = [];
            //商品销售额
            var productAmount = [];
            //遍历获取商品号
            for (let i = 0; i < dataList.length; i++) {
                names.push(dataList[i].cost);
                productAmount.push(dataList[i].num);
            }
            //设置表格参数
            option = {
                xAxis: {
                    type: 'category',
                    data: names,
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    data: productAmount,
                    type: 'bar',
                    showBackground: true,
                    backgroundStyle: {
                        color: 'rgba(220, 220, 220, 0.8)'
                    }
                }]
            };
            //给表格设置数据
            myChart.setOption(option);
        },
    });

    //页面加载完执行
    $(function () {
        getSystemParam();

        setInterval(getSystemParam, 10000);

    })

    //获取页面参数并回填
    function getSystemParam() {

        $.ajax({
            url: "/manage/index/param",
            method: "post",
            success: function (result) {

                $("#order-count").text(result.orderCount);
                $("#today-order").text(result.todayOrder);
                $("#download-count").text(result.downloadCount);
                $("#online-count").text(result.onlineCount);
            }
        })

    }


</script>
</body>
</html>
